package com.paic.mhis.hcpms.monitor.web.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.paic.mhis.core.auth.biz.service.UserDetails;
import com.paic.mhis.hcpms.monitor.biz.service.MonitorIntegrityService;
import com.paic.mhis.hcpms.monitor.web.vo.MonitorIntegrityVO;
import com.paic.pafa.appclient.annotation.BizServicesProxy;

/**
 * 诚信监控
 * 
 * @author EX-XIEQI001
 * 
 */
@Controller
@RequestMapping("/monitorIntegrity/")
public class MonitorIntegrityController {

	@BizServicesProxy
	private MonitorIntegrityService monitorIntegrityService;

	/**
	 * 获取诚信监控展示数据
	 * 
	 * @param vo
	 * @param request
	 * @return
	 */
	@RequestMapping("queryMonitorIntegrity.do")
	@ResponseBody
	public Map<String, Object> queryMonitorIntegrity(@ModelAttribute MonitorIntegrityVO vo, HttpServletRequest request) {
		Map<String, Object> result = new HashMap<String, Object>();
		Map<String, Object> map = new HashMap<String, Object>();
		// UserDetails user = (UserDetails)
		// request.getSession().getAttribute("user");

		// 案件类型
		if (null != vo && vo.getCaseTypes() != null && vo.getCaseTypes().size() > 0) {
			map.put("caseTypes", vo.getCaseTypes());
		}

		// 开始日期
		if (null != vo && StringUtils.isNotBlank(vo.getStartDate()) && StringUtils.isNotEmpty(vo.getStartDate())) {
			map.put("startDate", vo.getStartDate());
		}

		// 结束日期
		if (null != vo && StringUtils.isNotBlank(vo.getEndDate()) && StringUtils.isNotEmpty(vo.getEndDate())) {
			map.put("endDate", vo.getEndDate());
		}
		List<String > orgLevels = new ArrayList<String>();
		if (null != vo && null != vo.getOrgLevels() && vo.getOrgLevels().size() > 0) {
			orgLevels = vo.getOrgLevels();
		}
		result = monitorIntegrityService.queryMonitorIntegrity(map, orgLevels);
		return result;
	}

	/**
	 * 获取诚信监控重点监控数据
	 * 
	 * @param vo
	 * @param request
	 * @return
	 */
	@RequestMapping("queryKeyMonitoring.do")
	@ResponseBody
	public Map<String, Object> queryKeyMonitoring(HttpServletRequest request) {
		Map<String, Object> result = new HashMap<String, Object>();
		result = monitorIntegrityService.queryKeyMonitoring();
		return result;
	}

	/**
	 * 获取诚信监控地图数据
	 * 
	 * @param vo
	 * @param request
	 * @return
	 */
	@RequestMapping("queryMonitorIntegrityMap.do")
	@ResponseBody
	public Map<String, Object> queryMonitorIntegrityMap(@ModelAttribute MonitorIntegrityVO vo,
			HttpServletRequest request) {
		Map<String, Object> result = new HashMap<String, Object>();

		Map<String, Object> map = new HashMap<String, Object>();
		UserDetails user = (UserDetails) request.getSession().getAttribute("user");

		// 案件类型
		if (vo != null && vo.getCaseTypes() != null && vo.getCaseTypes().size() > 0) {
			map.put("caseTypes", vo.getCaseTypes());
		}

		// 开始日期
		if (vo != null && StringUtils.isNotBlank(vo.getStartDate()) && StringUtils.isNotEmpty(vo.getStartDate())) {
			map.put("startDate", vo.getStartDate());
		}

		// 结束日期
		if (vo != null && StringUtils.isNotBlank(vo.getEndDate()) && StringUtils.isNotEmpty(vo.getEndDate())) {
			map.put("endDate", vo.getEndDate());
		}
		result = monitorIntegrityService.queryMonitorIntegrityMap(map, user.getUserId());

		return result;
	}

}
